//添加一个支持返回到来源页面的混入
export const goBackMixin = {
  data() {
    return {
      fromPath: null,
      alreadyIni: false
    }
  },
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      if (!vm.alreadyIni) {
        vm.fromPath = from.path
      }
    })
  },
  mounted() {
    this.alreadyIni = true
  },

  methods: {
    goBack(refresh) {//跳转到来源页面
      this.$tab.closePage()
        .then(() => {
          let route = {
            path: this.fromPath,
            query: {
              refresh: refresh,
            },
          }
          this.$router.push(route)
        })
    }
  },
}

//添加一个支持返回到来源页面的混入
export const refreshMixin = {
  activated(option) {
    if (this.$route?.query?.refresh === "true") {//判断是否需要刷新
      this.getList();
    }
  },
}

//添加一个支持返回到来源页面的混入
// 增加(Create)、读取(Read)、更新(Update)和删除(Delete) 和审核(Audit)

export const editMixin = {
  computed: {
    readOnly() {
      let o = this.$route?.query?.o;
      return 'r' == o
    },
    update() {
      let o = this.$route?.query?.o;
      return 'c' == o || 'u' == o
    },
    audit() {//审核
      let o = this.$route?.query?.o;
      return 'a' == o;
    }
  },
}

